package com.ecfront.dao.impl;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.ecfront.dao.SupplierDAO;
import com.ecfront.pojo.Supplier;


/**
 * @version 1.0
 * @author www.ecfrom.com
 */

public class SupplierDAOImpl extends HibernateDaoSupport implements SupplierDAO {

	protected void initDao() {}

	public void save(Supplier transientInstance) {
		getHibernateTemplate().saveOrUpdate(transientInstance);
	}


	public void delete(Supplier persistentInstance) {
		getHibernateTemplate().delete(persistentInstance);
	}


	public Supplier findById(java.lang.Integer id) {
		Supplier instance = (Supplier) getHibernateTemplate().get(
					"com.ecfront.dao.impl.Supplier", id);
		return instance;
	}


	public List findByExample(Supplier instance) {
		List results = getHibernateTemplate().findByExample(instance);
		return results;
	}

	public List findByProperty(String propertyName, Object value) {
		String queryString = "from Supplier as model where model."
					+ propertyName + "= ?";
		return getHibernateTemplate().find(queryString, value);
	}

	public List findBySuName(Object suName) {
		return findByProperty(SU_NAME, suName);
	}

	public List findBySuGoods(Object suGoods) {
		return findByProperty(SU_GOODS, suGoods);
	}

	public List findBySuAdd(Object suAdd) {
		return findByProperty(SU_ADD, suAdd);
	}

	public List findBySuContact(Object suContact) {
		return findByProperty(SU_CONTACT, suContact);
	}

	public List findBySuPhone(Object suPhone) {
		return findByProperty(SU_PHONE, suPhone);
	}

	public List findBySuQq(Object suQq) {
		return findByProperty(SU_QQ, suQq);
	}

	public List findBySuEmail(Object suEmail) {
		return findByProperty(SU_EMAIL, suEmail);
	}

	public List findBySuWebSite(Object suWebSite) {
		return findByProperty(SU_WEB_SITE, suWebSite);
	}

	public List findAll() {
		String queryString = "from Supplier";
		return getHibernateTemplate().find(queryString);
	}

	public static SupplierDAO getFromApplicationContext(ApplicationContext ctx) {
		return (SupplierDAO) ctx.getBean("SupplierDAO");
	}
}